<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html>
<head>
<title>质量指标</title>
<base target="_self" />
<link rel="stylesheet" type="text/css"
	href="<s:url value="/resources"/>/css/geren.css" />
<link rel="stylesheet"
	href="<s:url value="/resources"/>/css/innerstyle.css" type="text/css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="<s:url value="/resources"/>/css/custom-theme/jquery-ui.custom.min.css" />
<!--<script type='text/javascript' src='<s:url value="/resources"/>//glqt/dwr/util.js'></script>
<script type='text/javascript' src='<s:url value="/resources"/>//glqt/dwr/engine.js'></script>
<script type='text/javascript' src='<s:url value="/resources"/>//glqt/dwr/interface/htdwr.js'></script>
<script type='text/javascript' src='<s:url value="/resources"/>//glqt/dwr/interface/jydz.js'></script>-->
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/jquery.form.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/json2.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/jquery.validate.min.js"></script>
<script type='text/javascript'>
	$(function(){
	   loadChange();  
	});
	function onChangePinp(pinpid) {
		var url = "<s:url value="/"/>/common/changePinp?pinpId=" + pinpid;
		if (pinpid == "-1") {
			$("#pinzs").show();
			$("#meizs").show();
			$("#pinz").val(""); //pinzmc
			$("#meiz").val("");
			$("#pinz").css("display", "none");
			$("#meiz").css("display", "none");
			$("#pinz").attr("disabled", false);
			$("#meiz").attr("disabled", false);
			
			var url3 = "<s:url value="/"/>/common/loadHtzb";
			$.get(
					url3,
					function(data) {
						$("#mr").children().remove();
						var projects = eval('(' + data + ')');
						var zb;
	for ( var i = 0; i < projects.length; i++) {
									//alert(projects[i].zhibmc);
									zb=
													zb+"<tr><td align='center'>"
															+ projects[i].zhibmc
															+ "<input type='hidden' id='zhibmc"+i+"' name='zhibmc' value='"+projects[i].zhibmc+"'/>"
															+ "<input type='hidden' id='zhibid"+i+"' name='zhibid' value='"+projects[i].zhibid+"'/>"
															+ "</td><td align='center'>"
															+ projects[i].fuh
															+ "<input type='hidden'  id='fuh"+i+"' name='fuh' value='"+projects[i].fuh+"'/>"
															+ "</td><td align='center'><input type='text' id='shangxz"+i+"' name='shangxz'  />"
															+ "</td><td align='center'><input type='text' id='xiaxz"+i+"' name='xiaxz'  />"
															+ "</td></tr>";
								}
	$("#mr").append(zb);
							});
		} else {
			$.get(url, function(data) {
				var projects = eval('(' + data + ')');
				//alert(data);
				$("#pinzs").hide();
				$("#meizs").hide();
				
				$("#pinz").css("display", "block");
				$("#meiz").css("display", "block");
				//alert(projects.pinzmc);
				$("#pinz").val(projects.pinzmc); //pinzmc
				$("#meiz").val(projects.meizmc);
				
				$("#pinzid").val(projects.pinz); //pinzmc
				$("#meizid").val(projects.meiz);
				
				$("#pinz").attr("disabled", true);
				$("#meiz").attr("disabled", true);

			});
			var url2 = "<s:url value="/"/>/common/findZBByPinp?pinpid="
					+ pinpid;

				$
					.get(
							url2,
							function(data) {
								var projects = eval('(' + data + ')');
								var zb;
								$("#mr").children().remove();
								for ( var i = 0; i < projects.length; i++) {
									
									

									

									zb=
										zb+"<tr><td align='center'>"
															+ projects[i].zhibmc
															+ "<input type='hidden' id='zhibmc"+i+"' name='zhibmc' value='"+projects[i].zhibmc+"'/>"
															+ "<input type='hidden' id='zhibid"+i+"' name='zhibid' value='"+projects[i].zhibid+"'/>"
															+ "</td><td align='center'>"
															+ projects[i].fuh
															+ "<input type='hidden'  id='fuh"+i+"' name='fuh' value='"+projects[i].fuh+"'/>"
															+ "</td><td align='center'><input type='text' id='shangxz"+i+"' name='shangxz' value='"+projects[i].shangxz+"'/>"
															+ "</td><td align='center'><input type='text' id='xiaxz"+i+"' name='xiaxz' value='"+projects[i].xiaxz+"'/>"
															+ "</td></tr>";
								}
								
								$("#mr").append(zb);

							});
		}

	}

	function setZBValue() {
		var pinp = $("#pinp").val();
		var pinpmc = $("#pinp").find("option:selected").text();
		var meiz;
		var pinz;
		var meizmc;
		var pinzmc;

		if (pinp == "-1") {
			meiz = $("#meiz2").val();
			pinz = $("#pinz2").val();
			meizmc = $("#meiz2").find("option:selected").text();
			pinzmc = $("#pinz2").find("option:selected").text();
		} else {
			meiz = $("#meizid").val();
			pinz = $("#pinzid").val();
			meizmc = $("#meiz").val();
			pinzmc = $("#pinz").val();
		}

		var zhibmc = $("#zhibmc").val();
		var fuh = $("#fuh").val();
		var shangxz = $("#shangxz").val();
		var xiaxz = $("#xiaxz").val();

		var zlzb = "";
		var ary = [];
		var aryxs = [];

		var j = -1;
		$("#mtzb").find("tr").each(function() {

			var djzb = new Object;
			var a = "", b = "";
			$(this).find("td").each(function() {
				if ($(this).find("[id='zhibmc" + j + "']").length > 0) {

					djzb.zhibmc = $(this).find("[id='zhibmc" + j + "']").val();
				}
				if ($(this).find("[id='zhibid" + j + "']").length > 0) {
					djzb.zhibid = $(this).find("[id='zhibid" + j + "']").val();

				}
				if ($(this).find("[id='fuh" + j + "']").length > 0) {
					var fh = $(this).find("[id='fuh" + j + "']").val();
					//特殊符号转码                             
					djzb.fuh = fh;
					//   djzb.fuh=fh;                                                
					if (fh == "-") {
						a = "";
						b = fh;
					} else if (fh == ">" || fh == "≥") {
						a = fh;
						b = "";
					} else if (fh == "<" || fh == "≤") {
						a = "";
						b = fh;
					}
				}
				if ($(this).find("[id='xiaxz" + j + "']").length > 0) {
					var xx = $(this).find("[id='xiaxz" + j + "']").val();
					if (xx != '') {
						djzb.xiaxz = xx;
					} else {
						djzb.xiaxz = '';
					}
				}
				if ($(this).find("[id='shangxz" + j + "']").length > 0) {
					var sx = $(this).find("[id='shangxz" + j + "']").val();
					if (sx != '') {
						djzb.shangxz = sx;
					} else {
						djzb.shangxz = '';
					}
				}

			});

			// djzb.fenzbm=i;
			aryxs[j] = djzb;

			ary[j] = JSON.stringify(djzb);

			//alert(ary[j]);

			j++;
		});

		var str1 = "";
		for (k = 0; k < j; k++) {
			// alert(aryxs[k].zhibmc);
			var fh = aryxs[k].fuh;
			var xx = aryxs[k].xiaxz;
			var sx = aryxs[k].shangxz;
			var zb = aryxs[k].zhibmc

			if (fh == "-") {
				if (xx != '') {
					if (sx != '') {
						str1 = str1 + zb + " " + xx + fh + sx + ";";
					} else {
						str1 = str1 + zb + " " + "≥" + xx + ";";
					}
				} else if (sx != '') {
					str1 = str1 + zb + " " + "≤" + sx + ";";
				} else {
				}

			} else if (fh == ">" || fh == "≥") {
				if (xx != '') {
					str1 = str1 + zb + " " + fh + xx + ";";
				}

			} else if (fh == "<" || fh == "≤") {
				if (sx != '') {
					str1 = str1 + zb + " " + fh + sx + ";";
				}
			}
		}

		zlzb = str1;

		var MyArgs = new Array(pinp, meiz, pinz, meizmc, pinzmc, zlzb, ary
				.toString(), pinpmc);
		window.returnValue = MyArgs;
		window.close();
	}
	function loadChange(){
		   var parent=window.dialogArguments;
		   var pinp = parent.document.getElementById("pinpid").value;
		   var meiz= parent.document.getElementById("meiz").value;
		   var pinz= parent.document.getElementById("pinz").value;
		   var meizmc= parent.document.getElementById("meizmc").value;
		   var pinzmc= parent.document.getElementById("pinzmc").value;
		   var zlzbs= parent.document.getElementById("zlzbs").value;
	
		   if(pinp==""){
			  
		   }else if(pinp=="-1"){
			   $("#pinp").val("-1");
			   $("#meiz2").val(meiz);
			   $("#pinz2").val(pinz);
			   
			   
			   $("#pinzs").show();
				$("#meizs").show();
				$("#pinz").val(""); //pinzmc
				$("#meiz").val("");
				$("#pinz").css("display", "none");
				$("#meiz").css("display", "none");
				$("#pinz").attr("disabled", false);
				$("#meiz").attr("disabled", false);
				
				
				$("#mr").children().remove();
				var projects = eval('(' + zlzbs + ')');
				var zb;
				for ( var i = 0; i < projects.length; i++) {
					//alert(projects[i].zhibmc);
					zb = zb
							+ "<tr><td align='center'>"
							+ projects[i].zhibmc
							+ "<input type='hidden' id='zhibmc"+i+"' name='zhibmc' value='"+projects[i].zhibmc+"'/>"
							+ "<input type='hidden' id='zhibid"+i+"' name='zhibid' value='"+projects[i].zhibid+"'/>"
							+ "</td><td align='center'>"
							+ projects[i].fuh
							+ "<input type='hidden'  id='fuh"+i+"' name='fuh' value='"+projects[i].fuh+"'/>"
							+ "</td><td align='center'><input type='text' id='shangxz"+i+"' name='shangxz' value='"+projects[i].shangxz+"'/>"
							+ "</td><td align='center'><input type='text' id='xiaxz"+i+"' name='xiaxz' value='"+projects[i].xiaxz+"'/>"
							+ "</td></tr>";
				}
				$("#mr").append(zb);

		} else {
			$("#pinp").val(pinp);

			$("#pinzs").hide();
			$("#meizs").hide();

			$("#pinz").css("display", "block");
			$("#meiz").css("display", "block");
			//alert(projects.pinzmc);

			$("#pinz").attr("disabled", true);
			$("#meiz").attr("disabled", true);

			$("#meiz").val(meizmc);
			$("#pinz").val(pinzmc);

			$("#mr").children().remove();
			var projects = eval('(' + zlzbs + ')');
			var zb;
			for ( var i = 0; i < projects.length; i++) {
				//alert(projects[i].zhibmc);
				zb = zb
						+ "<tr><td align='center'>"
						+ projects[i].zhibmc
						+ "<input type='hidden' id='zhibmc"+i+"' name='zhibmc' value='"+projects[i].zhibmc+"'/>"
						+ "<input type='hidden' id='zhibid"+i+"' name='zhibid' value='"+projects[i].zhibid+"'/>"
						+ "</td><td align='center'>"
						+ projects[i].fuh
						+ "<input type='hidden'  id='fuh"+i+"' name='fuh' value='"+projects[i].fuh+"'/>"
						+ "</td><td align='center'><input type='text' id='shangxz"+i+"' name='shangxz' value='"+projects[i].shangxz+"'/>"
						+ "</td><td align='center'><input type='text' id='xiaxz"+i+"' name='xiaxz' value='"+projects[i].xiaxz+"'/>"
						+ "</td></tr>";
			}
			$("#mr").append(zb);
		}

	}
</script>
<style type="text/css">
.mainuser-button {
	background-image: url('<s:url value="/resources"/>/img/Button_bg.jpg');
	background-repeat: repeat-x;
	font-size: 12px;
	text-align: center;
	border: solid 1px #C9B883;
}
</style>

</head>
<body style="margin: 10px; font-size: 9pt;">
	<form id='zbform'>
	<input type="hidden" name="pinzid" id="pinzid"/>
	<input type="hidden" name="meizid" id="meizid"/>
		<table cellpadding='3' cellspacing='1' class="datalist" id="bt">
			<tr class="altrow">
				<td>品牌名称<span style="color: #FF3300; font-weight: bold;">*</span>：</td>
				<td colspan="3"><select name="pinp" id="pinp" style="width:180px"
					onchange="onChangePinp(this.value);">
						<option value="-1" selected>==请选择==</option>
						<c:forEach var="pp" items="${pinp}">
							<option value="${pp.pinpid}">${pp.pinpmc}</option>
						</c:forEach>
				</select></td>
			</tr>
			<tr>
				<td>煤种：</td>
				<td style="width: 100px;">
					<div id="meizs">
						<select name="meiz" id="meiz2" style="width:180px">
							<option value="-1" selected>==请选择==</option>
							<c:forEach var="mz" items="${meiz}">
								<option value="${mz.diccode}">${mz.dicname}</option>
							</c:forEach>
						</select>
					</div> <input type="text" name="meiz" id="meiz" style="display:none;" />
				</td>
				<td style="width: 100px;">品种：</td>
				<td>
					<div id="pinzs">
						<select name="pinz" id="pinz2" style="width:180px">
							<option value="-1" selected>==请选择==</option>
							<c:forEach var="pz" items="${pinz}">
								<option value="${pz.diccode}">${pz.dicname}</option>
							</c:forEach>
						</select>
					</div> <input type="text" name="pinz" id="pinz" style="display:none;" />
				</td>
			</tr>
			<tr class="altrow">
				<td colspan="4">
					<h4>煤炭指标</h4>
				</td>
			</tr>
			<tr>
				<td colspan="4">
					<div
						style="height: 200px; overflow: scroll; overflow-x: hidden; width: 100%;">
						<table id="mtzb">
							<tr>
								<th width="150">名称</th>
								<th width="150">符号</th>
								<!--<th width="150">单位</th> -->
								<th width="150">下限指标</th>
								<th width="150">上限指标</th>
							</tr>
							<tbody id="mr">
								<c:forEach var="zlzb" items="${zlzb}" varStatus="status">
									<tr>
										<td align="center" >${zlzb.zhibmc}
										<input type="hidden" id="zhibmc${status.index}" name="zhibmc" value="${zlzb.zhibmc}"/>
										<input type="hidden" id="zhibid${status.index}" name="zhibid" value="${zlzb.zhibid}"/>
										</td>
										<td align="center" >${zlzb.fuh}
										<input type="hidden" id='fuh${status.index}' name="fuh" value="${zlzb.fuh}"/>
										</td>
										<!-- <td align="center" >${zlzb.danw}
										<input type="hidden" id='danw${status.index}' name="danw" value="${zlzb.danw}"/>
										</td> -->
										<td><input type="text" id='shangxz${status.index}' name="shangxz" /></td>
										<td><input type="text" id='xiaxz${status.index}' name="xiaxz" /></td>
									</tr>
								</c:forEach>
								</div>
							</tbody>
						</table>
					</div>
				</td>
			</tr>
			<tr class="altrow">
				<td colspan="2" style="height: 27px;" align="right">&nbsp;</td>
				<td colspan="2" align="right"><input id="btnSub" type="button"
					value="保存" class="mainuser-button" onclick="setZBValue()"
					style="width: 80px;" /> <input id="btnClose" type="button"
					value="取消" class="mainuser-button" onclick="window.close()"
					style="width: 80px;" /></td>
			</tr>
		</table>
	</form>
</body>
</html>
<script type='text/javascript'>
	
</script>
